
using System;
using System.IO;
using AtDevice;

namespace Interoperability
{
    
    
    public class PhonebookVcardExport : IPhonebookExport
    {
        private void WriteVcardEntry(StreamWriter writer, PhoneBookEntry entry)
        {
            writer.Write("BEGIN:VCARD\n");
            writer.Write("VERSION:3.0\n");
            writer.Write(String.Format("FN:{0}\n", entry.Name));
            writer.Write(String.Format("TEL;TYPE=CELL:{0}\n", entry.MobileNumber));
            writer.Write("END:VCARD\n\n");
        }
        
        public void ExportPhonebook(IPhoneBook phonebook, string filename)
        {
            using(FileStream stream  = File.OpenWrite(filename))
            using(StreamWriter writer = new StreamWriter(stream))
            {
                foreach(var entry in phonebook.GetEntries())
                {
                    WriteVcardEntry(writer, entry);
                }
            }
        }

        public string GetDescription()
        {
            return "vCard export";
        }

        public string GetFileSuffix()
        {
            return ".vcf";
        }
    }
}
